// copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
// see COPYRIGHT for reuse legalities
//

#import "RIBSolidBegin.h"

@implementation RIBSolidBegin

+ initialize { return [RIBSolidBegin setVersion:1], self; }

- init
{
  [super init];

  operation = RI_PRIMITIVE;
  
  return self;
}

- (BOOL)pushesOrPopsCTM { return YES; }
- (BOOL)pushesCTM { return YES; }

- setOperation:(RtToken)opName
{
  if (!strcmp(opName, RI_PRIMITIVE))
  {  operation = RI_PRIMITIVE;
     return self;
  }
  if (!strcmp(opName, RI_INTERSECTION))
  {  operation = RI_INTERSECTION;
     return self;
  }
  if (!strcmp(opName, RI_UNION))
  {  operation = RI_UNION;
     return self;
  }
  if (!strcmp(opName, RI_DIFFERENCE))
  {  operation = RI_DIFFERENCE;
     return self;
  }

  NXLogError("unknown solid operation <%s> in RIBCommand RIBSolidBegin ", opName);
  NXLogError("- supported operations are: primitive, intersection, union, difference.\n");
  return nil;
}

- (RtToken)operation { return operation; }

- renderSelf:(WW3DCamera *)camera startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
{
  RiSolidBegin(operation);

  return self;
}

- writeEve:(NXStream *)stream atTabLevel:(int)tab
{
   int  i;


   for (i = 0; i < tab; i++)
   {  NXPrintf(stream, "\t");
   }
   NXPrintf(stream, "SolidBegin %s;", operation); 
   return self;
}

#define typeVector "*"
#define typeValues &operation

- read:(NXTypedStream*)stream 
{
    int version;
    [super read:stream];

    version = NXTypedStreamClassVersion(stream,"RIBSolidBegin");
    if (version == 0) NXReadTypes(stream, "i", &version), version=1;
    if (version == 1)
    {  NXReadTypes(stream, typeVector, typeValues);
    } 
    else 
    {
    }
    return self;
}

- write:(NXTypedStream*)stream 
{
    [super write:stream];

    NXWriteTypes(stream, typeVector, typeValues);

    return self;
}

@end
